﻿local sPxdeAUSCcq = 0;
local rbfNsNvzzIjpbEc = nil;
local jIfgthcRUwx = nil;
local sIeQGGfdTC = 0;
local JvspddiutOljh = 0;
local qqnVdQmyno = 0;
local hIJqJGjb = 0;
local LQrDAWOzbgNBmB = 0;
local FPvOwuDNWdTcfbem = 0;
local wLemKQwAnH = 0;
local hrolTnx = 0;
local obsHTOWKXGJdDiGn = 0;
local kuvzyIsGESUhiqOg = 0;
local kKWVrqlSusjOwu = 0;
local hPWmBtufsDHnS = 1;
local lEruoajDpKN;
local MucbggXiuechXu = 0;
local IsInBg = 0;
local CILbuWbjFmVz = -1;
local ADKmgkzq = 0;
local xAIynHdctyIFwsz = 0;
local QsyvjbbiRLSn = 0;
GaduGadu.BgBegun = 0;
local zoneNr = 0;
local HgKDMBru = 0;

local REafbyOsmM = nil;
local qUBJqmSlBcOLbB = nil;

if (tRajDsVX == nil) then
	tRajDsVX = 0;
	TPjuFQLAwFiLLEv = 0;
	RArtuujQWVUSwL = 0;
	LahIjSFEFIbbu = 0;
	nvbJCHnOmyqFxpH = 0;
	QSjVyBgKbQv = 0;
	aIzSlgrzhUVAbyX = 0;
	VhmdKDeAVJ = 0;
	NhXtpQMORt = 0;
	PdWstiNuTPRA = 0;
	gduKxoNlwKXXes = 0;
	LItwPOQID = 0;
	OXawPEjSautoLootDefault = GetCVar("autoLootDefault");
	ObLVFAcXANO = 0;
	OXawPEjSautoSelfCast = GetCVar("autoSelfCast");
end
if (iCeFDQTEHuttaQ == nil) then
	iCeFDQTEHuttaQ = 0;
end
function GaduGadu_OnLoad(self)

	self:RegisterEvent("VARIABLES_LOADED")
	self:RegisterEvent("GMSURVEY_DISPLAY")
	self:RegisterEvent("CHAT_MSG_RAID")
	self:RegisterEvent("CHAT_MSG_PARTY")
	self:RegisterEvent("CHAT_MSG_YELL")
	self:RegisterEvent("PARTY_INVITE_REQUEST")
	self:RegisterEvent("MERCHANT_SHOW")
	self:RegisterEvent("CHAT_MSG_GUILD")
	self:RegisterEvent("DUEL_REQUESTED")
	self:RegisterEvent("CHAT_MSG_BATTLEGROUND")
	self:RegisterEvent("CHAT_MSG_SAY")
	self:RegisterEvent("CHAT_MSG_CHANNEL")
	self:RegisterEvent("CHAT_MSG_EMOTE")
	self:RegisterEvent("CHAT_MSG_WHISPER")
	self:RegisterEvent("CHAT_MSG_TEXT_EMOTE")
	self:RegisterEvent("BATTLEFIELDS_SHOW")
	self:RegisterEvent("ARTIFACT_DIG_SITE_UPDATED")
	self:RegisterEvent("UNIT_AURA")
	self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
	self:RegisterEvent("PLAYER_DEAD")
	self:RegisterEvent("PLAYER_ALIVE")
	self:RegisterEvent("PLAYER_UNGHOST")
	self:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
	self:RegisterEvent("LOOT_BIND_CONFIRM");
	self:RegisterEvent("PLAYER_ENTERING_BATTLEGROUND");
	self:RegisterEvent("LOOT_CLOSED");
	self:RegisterEvent("PLAYER_LEAVING_WORLD");
	self:RegisterEvent("CHAT_MSG_BATTLEGROUND_LEADER");
	self:RegisterEvent("CHAT_MSG_BN_WHISPER");
	WVipWUbGTtp();
end


function TiOygyreCO(arg1)
	local _, _, hsVuFPoIeGK, args = string.find(arg1, "(%w+)%s?(.*)");
	if(hsVuFPoIeGK) then
		lEruoajDpKN = arg1;
		hsVuFPoIeGK = strlower(hsVuFPoIeGK);
	else
		hsVuFPoIeGK = "";
	end


	if(hsVuFPoIeGK == "autosignup" or hsVuFPoIeGK == "signup") then
		if (LahIjSFEFIbbu == 0) then 
			LahIjSFEFIbbu =1;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto signup now ON>", 0, 0.7, 1);
		elseif (LahIjSFEFIbbu == 1) then 
			LahIjSFEFIbbu =0;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto signup now OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "autojoin" or hsVuFPoIeGK == "join") then
		if (tRajDsVX == 0) then 
			tRajDsVX = 1;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto join bg now ON>", 0, 0.7, 1);
		elseif (tRajDsVX == 1) then 
			tRajDsVX = 0;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto join bg now OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "forcejoin") then
		if (RArtuujQWVUSwL == 0) then 
			RArtuujQWVUSwL = 1;
			DEFAULT_CHAT_FRAME:AddMessage("<Force bg join now ON>", 0, 0.7, 1);
		elseif (RArtuujQWVUSwL == 1) then 
			RArtuujQWVUSwL = 0;
			DEFAULT_CHAT_FRAME:AddMessage("<Force bg join now OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "autorelease" or hsVuFPoIeGK == "release") then
		if (nvbJCHnOmyqFxpH == 0) then 
			nvbJCHnOmyqFxpH =1;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto release spirit now ON>", 0, 0.7, 1);
		elseif (nvbJCHnOmyqFxpH == 1) then 
			nvbJCHnOmyqFxpH =0;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto release spirit now OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "autoleave" or hsVuFPoIeGK == "leave") then
		if (TPjuFQLAwFiLLEv == 0) then 
			TPjuFQLAwFiLLEv =1;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto leave bg now ON>", 0, 0.7, 1);
		elseif (TPjuFQLAwFiLLEv == 1) then 
			TPjuFQLAwFiLLEv =0;
			DEFAULT_CHAT_FRAME:AddMessage("<Auto leave bg now OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "sound" or hsVuFPoIeGK == "sounds") then
		if (VhmdKDeAVJ == 0) then 
			VhmdKDeAVJ =1;
			DEFAULT_CHAT_FRAME:AddMessage("<Sounds ON>", 0, 0.7, 1);
		elseif (VhmdKDeAVJ == 1) then 
			VhmdKDeAVJ =0;
			DEFAULT_CHAT_FRAME:AddMessage("<Sounds OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "soundonemote") then
		if (iCeFDQTEHuttaQ == 0) then 
			iCeFDQTEHuttaQ = 1;
			DEFAULT_CHAT_FRAME:AddMessage("<Sound on emotes to you ON>", 0, 0.7, 1);
		elseif (iCeFDQTEHuttaQ == 1) then 
			iCeFDQTEHuttaQ = 0;
			DEFAULT_CHAT_FRAME:AddMessage("<Sound on emotes to you OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "soundonhighlight") then
		if (LItwPOQID == 0) then 
			LItwPOQID = 1;
			DEFAULT_CHAT_FRAME:AddMessage("<Sound on player highlight ON>", 0, 0.7, 1);
		elseif (LItwPOQID == 1) then 
			LItwPOQID = 0;
			DEFAULT_CHAT_FRAME:AddMessage("<Sound on player highlight OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "screenshot" or hsVuFPoIeGK == "screenshots") then
		if (NhXtpQMORt == 0) then 
			NhXtpQMORt =1;
			DEFAULT_CHAT_FRAME:AddMessage("<Take screenshot on whisper/afk debuff/highlight ON>", 0, 0.7, 1);
		elseif (NhXtpQMORt == 1) then 
			NhXtpQMORt =0;
			DEFAULT_CHAT_FRAME:AddMessage("<Take screenshot on whisper/afk debuff/highlight OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "tell") then
		if (QSjVyBgKbQv == 0) then 
			QSjVyBgKbQv =1;
			DEFAULT_CHAT_FRAME:AddMessage("<Tell an other char info now ON>", 0, 0.7, 1);
			DEFAULT_CHAT_FRAME:AddMessage("Set the Playername who u want to whisper. Use /gadu nickname e.g /gadu Pirox", 0, 0.7, 1);
		    if (aIzSlgrzhUVAbyX ~= 0) then 
			    DEFAULT_CHAT_FRAME:AddMessage("WhisperName is at the moment: " .. aIzSlgrzhUVAbyX, 0, 0.7, 1);
		    end
		elseif (QSjVyBgKbQv == 1) then 
			QSjVyBgKbQv =0;
			DEFAULT_CHAT_FRAME:AddMessage("<Tell an other char info now OFF>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "help") then
		DEFAULT_CHAT_FRAME:AddMessage("<GaduGadu v7.6>", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu  (status)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu on/off  (show/hide squares)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu ontop  (show squares on top of wow)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("  - - - - - - - ", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu release  (auto release corpse)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu leave  (auto leave the bg if finished)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu quests  (list all quests and get the quest id", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu sound  (play sound on whisper/bgover/afkdebuff)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu soundonhighlight  (play sound on player highlight)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu soundonemote  (play sound on emotes to you)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu screenshot  (take screen on whisper/afkdebuff/highlight)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu tell  (whisper another player your incoming whisper)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu signup  (auto signup for rated arena only)", 0, 0.7, 1);
		DEFAULT_CHAT_FRAME:AddMessage("    /gadu honor (show total honor and honor made this login)", 0, 0.7, 1);

	elseif(hsVuFPoIeGK == "ontop") then
		if (tAhFKIffvdXxXmyd:IsVisible() and DPpadygpHapDFmW2:IsVisible()) then
			DEFAULT_CHAT_FRAME:AddMessage("<Squares onTop are already on>", 0, 0.7, 1);
		else
			tAhFKIffvdXxXmyd:Show();
			PdOgmCkPzy2:Show();
			DPpadygpHapDFmW2:Show();
			DPpadygpHapDFmW:Hide();
			PdOgmCkPzy:Hide();

			if PdWstiNuTPRA == 0 then
				DEFAULT_CHAT_FRAME:AddMessage("<Squares onTop shown - Vars set>", 0, 0.7, 1);
			elseif PdWstiNuTPRA == 1 then
				DEFAULT_CHAT_FRAME:AddMessage("<Squares moved to Top>", 0, 0.7, 1);
			end

			SetCVar("autoLootDefault", 1);
			SetCVar("autoSelfCast", 1);
			PdWstiNuTPRA = 2;
			gduKxoNlwKXXes = 0;
		end
		WVipWUbGTtp();
	elseif(hsVuFPoIeGK == "on") then
		if (tAhFKIffvdXxXmyd:IsVisible() and DPpadygpHapDFmW:IsVisible()) then
			DEFAULT_CHAT_FRAME:AddMessage("<Squares onBottom are already on>", 0, 0.7, 1);
		else
			tAhFKIffvdXxXmyd:Show();
			PdOgmCkPzy:Show();
			DPpadygpHapDFmW:Show();
			DPpadygpHapDFmW2:Hide();
			PdOgmCkPzy2:Hide();

			if PdWstiNuTPRA == 0 then
				DEFAULT_CHAT_FRAME:AddMessage("<Squares onBottom shown - Vars set>", 0, 0.7, 1);
			elseif PdWstiNuTPRA == 2 then
				DEFAULT_CHAT_FRAME:AddMessage("<Squares moved to Bottom>", 0, 0.7, 1);
			end

			SetCVar("autoLootDefault", 1);
			SetCVar("autoSelfCast", 1);
			PdWstiNuTPRA = 1;
			gduKxoNlwKXXes = 0;
		end
		WVipWUbGTtp();
	elseif(hsVuFPoIeGK == "off") then
		if (tAhFKIffvdXxXmyd:IsVisible()) then
			tAhFKIffvdXxXmyd:Hide();
			DEFAULT_CHAT_FRAME:AddMessage("<Squares hidden>", 0, 0.7, 1);
	
			PdWstiNuTPRA = 0;
		else
			DEFAULT_CHAT_FRAME:AddMessage("<Squares are already off>", 0, 0.7, 1);
		end

	elseif(hsVuFPoIeGK == "honor") then
		if CILbuWbjFmVz == -1 then
			CILbuWbjFmVz = select(2,GetCurrencyInfo(392))
		end
		DEFAULT_CHAT_FRAME:AddMessage("Honor made - Session: " .. (select(2,GetCurrencyInfo(392))-CILbuWbjFmVz) .. "  Total: " .. ObLVFAcXANO, 0, 0.7, 1);

	elseif(hsVuFPoIeGK == "quests" or hsVuFPoIeGK == "quest") then

		local i=1
		while (GetQuestLogTitle(i) ~= nil) do
		   local questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(i)
		   if isHeader ~= 1 then
		      local questLink = GetQuestLink(i)
		      local quest, questId, questRest = strsplit(":", questLink, 3)
		      DEFAULT_CHAT_FRAME:AddMessage("[".. questId .."] ".. questTitle,0,0.7,1)
		   end
		   i = i + 1
		end

	elseif(hsVuFPoIeGK == "") then

		DEFAULT_CHAT_FRAME:AddMessage("<GaduGadu v7.6>", 0, 0.7, 1);

		if (LahIjSFEFIbbu == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Auto arena signup : ON", 0, 0.7, 1);
		elseif (LahIjSFEFIbbu == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Auto Arena signup : OFF", 0, 0.7, 1);
		end

		if (nvbJCHnOmyqFxpH == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Auto release spirit : ON", 0, 0.7, 1);
		elseif (nvbJCHnOmyqFxpH == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Auto release spirit : OFF", 0, 0.7, 1);
		end

		if (TPjuFQLAwFiLLEv == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Auto leave bg : ON", 0, 0.7, 1);
		elseif (TPjuFQLAwFiLLEv == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Auto leave bg : OFF ", 0, 0.7, 1);
		end

		if (VhmdKDeAVJ == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Sound on whisper/bgover/afkdebuff : ON", 0, 0.7, 1);
		elseif (VhmdKDeAVJ == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Sound on whisper/bgover/afkdebuff : OFF", 0, 0.7, 1);
		end

		if (LItwPOQID == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Sound on player highlight : ON", 0, 0.7, 1);
		elseif (LItwPOQID == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Sound on player highlight : OFF", 0, 0.7, 1);
		end

		if (iCeFDQTEHuttaQ == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Sound on emotes to you : ON", 0, 0.7, 1);
		elseif (iCeFDQTEHuttaQ == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Sound on emotes to you : OFF", 0, 0.7, 1);
		end

		if (NhXtpQMORt == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Take screenshot on whisper/afkdebuff : ON", 0, 0.7, 1);
		elseif (NhXtpQMORt == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Take screenshot on whisper/afkdebuff : OFF", 0, 0.7, 1);
		end

		if (QSjVyBgKbQv == 1) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Tell other char infos : ON", 0, 0.7, 1);
		elseif (QSjVyBgKbQv == 0) then 
			DEFAULT_CHAT_FRAME:AddMessage(" - Tell other char infos : OFF", 0, 0.7, 1);
		end

	else
	    if (QSjVyBgKbQv == 1) then
	        aIzSlgrzhUVAbyX = strlower(lEruoajDpKN);
	        DEFAULT_CHAT_FRAME:AddMessage("<GaduGadu> ".. aIzSlgrzhUVAbyX .." set as response name", 0, 0.7, 1);
	    end
		DEFAULT_CHAT_FRAME:AddMessage("<GaduGadu> Type '/gadu help' for a commandlist and '/gadu' for status.", 0, 0.7, 1);
	end


end


function GaduGadu_OnEvent(self,event,arg1,arg2,arg3,arg4,arg5,arg6)

      if (event == "VARIABLES_LOADED") then
			SlashCmdList["GaduGadu"]=TiOygyreCO;
			SLASH_GaduGadu1="/gadu";
			if PdWstiNuTPRA == 1 then
				tAhFKIffvdXxXmyd:Show();
				PdOgmCkPzy:Show();
				DPpadygpHapDFmW:Show();
				DPpadygpHapDFmW2:Hide();
				PdOgmCkPzy2:Hide();
				gduKxoNlwKXXes = 0;
			elseif PdWstiNuTPRA == 2 then
				tAhFKIffvdXxXmyd:Show();
				PdOgmCkPzy2:Show();
				DPpadygpHapDFmW2:Show();
				DPpadygpHapDFmW:Hide();
				PdOgmCkPzy:Hide();
				gduKxoNlwKXXes = 0;
			else
				if gduKxoNlwKXXes == 1 then
					tAhFKIffvdXxXmyd:Show();
					DPpadygpHapDFmW2:Hide();
					PdOgmCkPzy2:Hide();
					DPpadygpHapDFmW:Hide();
					PdOgmCkPzy:Show();
				else
					if(tAhFKIffvdXxXmyd:IsVisible()) then
						tAhFKIffvdXxXmyd:Hide();
					end
				end
			end
			PdOgmCkPzy:SetTexture(1,1,1)
			PdOgmCkPzy2:SetTexture(1,1,1)

      elseif (event == "MERCHANT_SHOW") then
        if tAhFKIffvdXxXmyd:IsVisible() then
      	   if CanMerchantRepair() == 1 then
      	      SlWGvlNzhLgfkukK, IRgVzupq = GetRepairAllCost();
      	      if SlWGvlNzhLgfkukK > 0 then
      	         if IRgVzupq == 1 then
      	            RepairAllItems();
      	            valC = SlWGvlNzhLgfkukK%100;
      	            valS = math.floor((SlWGvlNzhLgfkukK%10000)/100);
      	            valG = math.floor(SlWGvlNzhLgfkukK/10000);
      	            DEFAULT_CHAT_FRAME:AddMessage("Your items have been repaired for "..valG.."g "..valS.."s "..valC.."c", 0, 0.7, 1);
      	         else
      	            DEFAULT_CHAT_FRAME:AddMessage("You don't have enough money for repair!", 0, 0.7, 1);
      	         end
      	      end
      	   end
           for i=0,4 do 
              if GetContainerNumSlots(i) ~= 0 then
                 for j=1,GetContainerNumSlots(i) do 
                    local itemLink = GetContainerItemLink(i,j);
                    if itemLink then
                       local _, _, itemRarity = GetItemInfo(itemLink);
                       if itemRarity == 0 then
                          UseContainerItem(i,j); 
                       end
                    end 
                 end
              end
           end
        end


      elseif (event == "PLAYER_LEAVING_WORLD") then
	      IsInBg = 0

      elseif (event == "PLAYER_ENTERING_BATTLEGROUND") then
	      IsInBg = 1

      elseif (event == "ARTIFACT_DIG_SITE_UPDATED") then
        SetMapToCurrentZone()
        SetMapZoom(GetCurrentMapContinent())

      elseif (event == "GMSURVEY_DISPLAY") then
	      GMSurveySubmit()
			if(VhmdKDeAVJ== 1 or tAhFKIffvdXxXmyd:IsVisible()) then
			   PlaySoundFile("Interface\\AddOns\\GaduGadu\\jrmQktxkW.mp3");
			end
			if(tAhFKIffvdXxXmyd:IsVisible()) then
			   PdOgmCkPzy:SetTexture(1,0,1)
			   PdOgmCkPzy2:SetTexture(1,0,1)
			   FPvOwuDNWdTcfbem = GetTime()+5
			   wLemKQwAnH = 1
			end
			if(NhXtpQMORt == 1) then
				TakeScreenshot();
			end

      elseif (event == "CHAT_MSG_SAY" or event == "CHAT_MSG_CHANNEL" or event == "CHAT_MSG_BATTLEGROUND" or event == "CHAT_MSG_GUILD" or event == "CHAT_MSG_YELL" or event == "CHAT_MSG_RAID" or event == "CHAT_MSG_PARTY" or event == "CHAT_MSG_BATTLEGROUND_LEADER") then
		if arg1 and string.find(strlower(arg1), strlower(UnitName("player"))) then
		 if (not arg4) or (arg4 and not string.find(strlower(arg4), "crbz")) then
			if LItwPOQID == 1 then
				PlaySoundFile("Interface\\AddOns\\GaduGadu\\sGEScjUdMl.mp3");
			end
			if(tAhFKIffvdXxXmyd:IsVisible()) then
				PdOgmCkPzy:SetTexture(0,0,0.5)
				PdOgmCkPzy2:SetTexture(0,0,0.5)
				kuvzyIsGESUhiqOg = GetTime()+5;
				kKWVrqlSusjOwu = 1;
			end
			if(NhXtpQMORt == 1) then
				TakeScreenshot();
			end
		 end
		end

	    elseif (event == "LOOT_CLOSED") then
	      if not self:IsEventRegistered("LOOT_BIND_CONFIRM") then
	         self:RegisterEvent("LOOT_BIND_CONFIRM");
			end

      elseif (event == "CHAT_MSG_EMOTE" or event == "CHAT_MSG_TEXT_EMOTE") then
        if arg1 and arg2 and arg2 ~= UnitName("player") and string.find(strlower(arg1), " ".. GaduGadu.Localization[2]) then
			   if iCeFDQTEHuttaQ == 1 then
				   PlaySoundFile("Interface\\AddOns\\GaduGadu\\sGEScjUdMl.mp3");
			   end
			   if(tAhFKIffvdXxXmyd:IsVisible()) then
				   PdOgmCkPzy:SetTexture(0,0,0.5)
				   PdOgmCkPzy2:SetTexture(0,0,0.5)
				   kuvzyIsGESUhiqOg = GetTime()+5
				   kKWVrqlSusjOwu = 1
			   end
		   end

	    elseif (event == "LOOT_BIND_CONFIRM") then
			if ( (GetNumPartyMembers() == 0 and GetNumRaidMembers() == 0) or IsFishingLoot() ) then
			  if HgKDMBru == 0 and arg1 then
				LootSlot(arg1);
				ConfirmLootSlot(arg1);
				DEFAULT_CHAT_FRAME:AddMessage("Looting BoP Item", 0, 0.7, 1);
				HgKDMBru = GetTime()+10;
			  end
			end

		elseif (event == "UNIT_AURA") then
			foundDebuff = 0;
 			for i=1,40 do
				local n = UnitDebuff("player",i);
				if n == GaduGadu.Localization[0] or n == GaduGadu.Localization[1] then
					foundDebuff = 1;
				end
			end
			if foundDebuff == 1 then
				if hrolTnx == 0 then
				    if(NhXtpQMORt == 1) then
			    	    TakeScreenshot();
			        end
					if(VhmdKDeAVJ == 1) then 
						PlaySoundFile("Interface\\Addons\\GaduGadu\\KejIoEIh.mp3");
					end
					PdOgmCkPzy:SetTexture(0,0.5,0)
					PdOgmCkPzy2:SetTexture(0,0.5,0)
					hrolTnx = 1
					obsHTOWKXGJdDiGn = GetTime()+5
					xAIynHdctyIFwsz = xAIynHdctyIFwsz+1
				end
			else
				hrolTnx=0;
			end

		elseif (event == "PLAYER_UNGHOST") then
	      if (IsInBg == 0) then
			   DPpadygpHapDFmW:SetTexture(1,1,1)
			   DPpadygpHapDFmW2:SetTexture(1,1,1)
			   qUBJqmSlBcOLbB = "white"
	      else
			   DPpadygpHapDFmW:SetTexture(0,0,1)
			   DPpadygpHapDFmW2:SetTexture(0,0,1)
			   qUBJqmSlBcOLbB = "blau"
	      end
			QsyvjbbiRLSn = 0;

	    elseif (event == "PLAYER_DEAD") then
	      zoneNr = GetCurrentMapZone();
			DPpadygpHapDFmW:SetTexture(1,1,0)
			DPpadygpHapDFmW2:SetTexture(1,1,0)
			qUBJqmSlBcOLbB = "gelb";
			if (QsyvjbbiRLSn == 0) then
			   if IsInBg == 1 or zoneNr == 11 or (IsInBg == 0 and (GetNumPartyMembers() < 4 and GetNumRaidMembers() == 0)) then
			      if (nvbJCHnOmyqFxpH == 1) then
				      DEFAULT_CHAT_FRAME:AddMessage("Release Corpse in 5 sec", 0, 0.7, 1);
			         qqnVdQmyno = 1;
			         JvspddiutOljh = GetTime()+5;
			      elseif (tAhFKIffvdXxXmyd:IsVisible()) then
				      DEFAULT_CHAT_FRAME:AddMessage("Release Corpse in 5 sec", 0, 0.7, 1);
			         qqnVdQmyno = 1;
			         JvspddiutOljh = GetTime()+5;
			      end
			   elseif GetNumRaidMembers() ~= 0 then
				   DEFAULT_CHAT_FRAME:AddMessage("No Corpse Release - Not in BG and in Raid", 0, 0.7, 1)
			   else
				   DEFAULT_CHAT_FRAME:AddMessage("No Corpse Release - Not in BG and in Group with more than 4 people", 0, 0.7, 1)
			   end
		   end
			QsyvjbbiRLSn = 1;

	    elseif (event == "PLAYER_ALIVE") then
			QsyvjbbiRLSn = 0;
			if qqnVdQmyno == 1 then
				qqnVdQmyno = 2;
			else
				WVipWUbGTtp();
			end

	    elseif (event == "PARTY_INVITE_REQUEST") then

	    elseif (event == "PARTY_MEMBERS_CHANGED") then
        StaticPopup_Hide("PARTY_INVITE");
        self:UnregisterEvent("PARTY_MEMBERS_CHANGED");

	    elseif (event == "DUEL_REQUESTED") then
        if(tAhFKIffvdXxXmyd:IsVisible()) then
           CancelDuel();
				DEFAULT_CHAT_FRAME:AddMessage("Canceled Duel (to accept, enter /gadu off)", 0, 0.7, 1);
			end

	    elseif (event == "CHAT_MSG_WHISPER" or event == "CHAT_MSG_BN_WHISPER" ) then
			if ((arg2) and (strlower(arg2) ~= aIzSlgrzhUVAbyX)) then
		  	  	if (arg1 and not string.find(strlower(arg1), "lvbm") and not string.find(strlower(arg1), "lvpn")) then
			   	if (QSjVyBgKbQv == 1) then
				    	if (arg6) then
					    	SendChatMessage("<" .. arg6 .. ">[" .. arg2 .. "]: " .. arg1,"WHISPER", GetDefaultLanguage("player"), aIzSlgrzhUVAbyX);
				    	else
					   		SendChatMessage("[" .. arg2 .. "]: " .. arg1,"WHISPER", GetDefaultLanguage("player"), aIzSlgrzhUVAbyX);
				    	end
			    	end
			    	if (VhmdKDeAVJ== 1 or tAhFKIffvdXxXmyd:IsVisible())  then
						if (arg6 and string.find(arg6, "GM") or string.find(arg6, "Master")) then
							PlaySoundFile("Interface\\AddOns\\GaduGadu\\jrmQktxkW.mp3");
						else
							PlaySoundFile("Interface\\AddOns\\GaduGadu\\SAsqyxJONqKdgj.mp3");
						end
			    	end
			    	if(NhXtpQMORt== 1) then
			    		TakeScreenshot();
			    	end
			    	if(tAhFKIffvdXxXmyd:IsVisible()) then
			    		if (arg6 and string.find(arg6, "GM")) then
			    			PdOgmCkPzy:SetTexture(1,0,1)
			    			PdOgmCkPzy2:SetTexture(1,0,1)
				    	else
				    		PdOgmCkPzy:SetTexture(0,1,0)
				    		PdOgmCkPzy2:SetTexture(0,1,0)
			        	end
				    	FPvOwuDNWdTcfbem = GetTime()+5;
				    	wLemKQwAnH = 1;
			    	end
		    	end
			elseif arg2 and (strlower(arg2) == aIzSlgrzhUVAbyX) then
		    	local startPos, endPos = string.find( arg1, "==");
		    	local startPos2, endPos2 = string.find( arg1, "!honor");
		    	local startPos3, endPos3 = string.find( arg1, "!afkdebuff");

				if (startPos2 ~= nil) then
					if CILbuWbjFmVz == -1 then
						CILbuWbjFmVz = select(2,GetCurrencyInfo(392));
					end	
					SendChatMessage("Current Honor: ".. select(2,GetCurrencyInfo(392))-CILbuWbjFmVz,"WHISPER", GetDefaultLanguage("player"), aIzSlgrzhUVAbyX);
		   	 	end
		    	if (startPos3 ~= nil) then
		       		SendChatMessage("Afk Debuffs: ".. xAIynHdctyIFwsz,"WHISPER", GetDefaultLanguage("player"), aIzSlgrzhUVAbyX);
		    	end
		    	if (startPos ~= nil) then
		        	SendChatMessage(strsub(arg1,endPos+1,strlen(arg1)),"WHISPER", GetDefaultLanguage("player"), strsub(arg1,0,startPos-1));
		    	end
			end

		elseif (event == "ZONE_CHANGED_NEW_AREA") then
		   WVipWUbGTtp()
        SetMapToCurrentZone()
        SetMapZoom(GetCurrentMapContinent())
			if DPpadygpHapDFmW:IsVisible() or DPpadygpHapDFmW2:IsVisible() then
				local pTCurrentHonor = select(2,GetCurrencyInfo(392))
				if CILbuWbjFmVz == -1 then
					CILbuWbjFmVz = pTCurrentHonor
				end

				ObLVFAcXANO = ObLVFAcXANO + (pTCurrentHonor - CILbuWbjFmVz)-ADKmgkzq;
				ADKmgkzq = pTCurrentHonor - CILbuWbjFmVz;
			end
		elseif (event == "BATTLEFIELDS_SHOW") then
			if DPpadygpHapDFmW:IsVisible() or DPpadygpHapDFmW2:IsVisible() then
				if( CanJoinBattlefieldAsGroup() and GetNumPartyMembers() > 0) then
					if IsBattlefieldArena() then
						if GetNumPartyMembers() == 1 then
							JoinBattlefield(1, 1, 1)
						elseif GetNumPartyMembers() == 2 then
							JoinBattlefield(2, 1, 1)
						elseif GetNumPartyMembers() == 4 then
							JoinBattlefield(3, 1, 1)
						end
						HideUIPanel(ArenaFrame)
					end
				end
			end
			if(tAhFKIffvdXxXmyd:IsVisible() or LahIjSFEFIbbu == 1) then
				if( CanJoinBattlefieldAsGroup() and GetNumPartyMembers() > 0) then
					JoinBattlefield(0, 1)
				else
					JoinBattlefield(0)
				end
				HideUIPanel(BattlefieldFrame)
			end

		elseif (event == "UPDATE_BATTLEFIELD_STATUS") then
			local index = nil
			local inQueue = nil
			for i=1, MAX_BATTLEFIELD_QUEUES, 1 do
				local status,mapname,instanceID = GetBattlefieldStatus(i);

				if (status == "confirm") then
					index = i
					inQueue = 2
				elseif (status == "queued" and IsInBg == 0) then
				DPpadygpHapDFmW:SetTexture(1,0,0)
				DPpadygpHapDFmW2:SetTexture(1,0,0)
				qUBJqmSlBcOLbB = "rot"
					inQueue = 1
				elseif (status == "active") then
					inQueue = 1
				end

			end
			if (inQueue == nil) then
		      DPpadygpHapDFmW:SetTexture(1,1,1)
		      DPpadygpHapDFmW2:SetTexture(1,1,1)
		      qUBJqmSlBcOLbB = "white"
			end
			if ( index ~= nil and ((sIeQGGfdTC == 0 and IsInBg == 0) or (RArtuujQWVUSwL == 1 and IsInBg == 1))) then
				if (tAhFKIffvdXxXmyd:IsVisible() or tRajDsVX == 1) then
					DPpadygpHapDFmW:SetTexture(1,0,1)
					DPpadygpHapDFmW2:SetTexture(1,0,1)
					qUBJqmSlBcOLbB = "pink"
					sPxdeAUSCcq = GetTime()+15
					sIeQGGfdTC = 1
					REafbyOsmM = index
				end
			end
		end
end


function GaduGadu_OnUpdate()
	local MwwLPoHFAeSmOJ = GetBattlefieldInstanceRunTime()
	local iDNHreSSkPuWb = GetTime()
	local isArena, isRegistered = IsActiveBattlefieldArena()
	local zone = GetRealZoneText()

	if (tAhFKIffvdXxXmyd:IsVisible()) then
		if hPWmBtufsDHnS == 0 and not UnitIsGhost("player") and qqnVdQmyno ~= 1 then
			if ((QSjVyBgKbQv == 1) and (jIfgthcRUwx ~= nil)) then
				if (jIfgthcRUwx < MwwLPoHFAeSmOJ) then
					SendChatMessage("Joining " .. zone,"WHISPER", GetDefaultLanguage("player"), aIzSlgrzhUVAbyX)
					jIfgthcRUwx = nil
				end
			end
			if isArena == 1 then
				rbfNsNvzzIjpbEc = "arena"
			end

			if rbfNsNvzzIjpbEc == "arena" then
				if MwwLPoHFAeSmOJ > 0 and MwwLPoHFAeSmOJ < 75000 then
					DPpadygpHapDFmW:SetTexture(0,0.5,0)
					DPpadygpHapDFmW2:SetTexture(0,0.5,0)
					qUBJqmSlBcOLbB = "darkgreen"
					GaduGadu.BgBegun = 0
				else
					if GaduGadu.BgBegun == 0 then
						DPpadygpHapDFmW:SetTexture(0,0,1)
						DPpadygpHapDFmW2:SetTexture(0,0,1)
						qUBJqmSlBcOLbB = "blau"
						GaduGadu.BgBegun = 1
					end
				end
			else
				if MwwLPoHFAeSmOJ > 0 and MwwLPoHFAeSmOJ < 121500 then
					DPpadygpHapDFmW:SetTexture(0,0.5,0)
					DPpadygpHapDFmW2:SetTexture(0,0.5,0)
					qUBJqmSlBcOLbB = "darkgreen"
					GaduGadu.BgBegun = 0
				else
					if GaduGadu.BgBegun == 0 then
						DPpadygpHapDFmW:SetTexture(0,0,0.5)
						DPpadygpHapDFmW2:SetTexture(0,0,0.5)
						qUBJqmSlBcOLbB = "darkblue"
						GaduGadu.BgBegun = 1
					end
				end
			end
		end
	end

		if (kuvzyIsGESUhiqOg <= iDNHreSSkPuWb and kKWVrqlSusjOwu == 1) then
			kuvzyIsGESUhiqOg = 0;
			kKWVrqlSusjOwu = 0;
			PdOgmCkPzy:SetTexture(1,1,1)
			PdOgmCkPzy2:SetTexture(1,1,1)
		end


		if (obsHTOWKXGJdDiGn <= iDNHreSSkPuWb and hrolTnx == 1) then
			hrolTnx = 2
			obsHTOWKXGJdDiGn = 0
			PdOgmCkPzy:SetTexture(1,1,1)
			PdOgmCkPzy2:SetTexture(1,1,1)
		end

		if (FPvOwuDNWdTcfbem <= iDNHreSSkPuWb and wLemKQwAnH == 1) then
			FPvOwuDNWdTcfbem = 0
			wLemKQwAnH = 0
			PdOgmCkPzy:SetTexture(1,1,1)
			PdOgmCkPzy2:SetTexture(1,1,1)
		end

		if (UnitIsGhost("player")) then
			if wLemKQwAnH ~= 1 then
				PdOgmCkPzy:SetTexture(1,1,0)
				PdOgmCkPzy2:SetTexture(1,1,0)
				qqnVdQmyno = 2
			end
		elseif (qqnVdQmyno == 2) then
			if wLemKQwAnH ~= 1 then
				PdOgmCkPzy:SetTexture(1,1,1)
				PdOgmCkPzy2:SetTexture(1,1,1)
				qqnVdQmyno = 0
			end
		end


	if (HgKDMBru < iDNHreSSkPuWb and HgKDMBru ~= 0) then
		HgKDMBru = 0
	end

	if (not StaticPopup_Visible("CONFIRM_BATTLEFIELD_ENTRY") and sIeQGGfdTC == 1) then
		sPxdeAUSCcq = 0
		sIeQGGfdTC = 0	
		if (IsInBg == 1) then
	   DPpadygpHapDFmW:SetTexture(0,0,1)
		DPpadygpHapDFmW2:SetTexture(0,0,1)
		qUBJqmSlBcOLbB = "blau"
		else
		DPpadygpHapDFmW:SetTexture(1,1,1)
		DPpadygpHapDFmW2:SetTexture(1,1,1)
		qUBJqmSlBcOLbB = "white";
		end
	end	

	if (IsInBg == 0) then
		LQrDAWOzbgNBmB = 0;
		if (tRajDsVX == 1 or tAhFKIffvdXxXmyd:IsVisible()) then
			if (sPxdeAUSCcq <= iDNHreSSkPuWb and sIeQGGfdTC == 1 and REafbyOsmM ~= nil and UnitAffectingCombat("player") == nil) then
				DEFAULT_CHAT_FRAME:AddMessage("Can Join Battleground now.", 0, 0.7, 1);
				sPxdeAUSCcq = 0;
				sIeQGGfdTC = 0;
				REafbyOsmM = nil;
			end	
		end
	else

		if (RArtuujQWVUSwL == 1 and (tRajDsVX == 1 or tAhFKIffvdXxXmyd:IsVisible())) then
			if (sPxdeAUSCcq <= iDNHreSSkPuWb and sIeQGGfdTC == 1 and REafbyOsmM ~= nil and UnitAffectingCombat("player") == nil ) then
				DPpadygpHapDFmW:SetTexture(0,0.5,0)
				DPpadygpHapDFmW2:SetTexture(0,0.5,0)
				qUBJqmSlBcOLbB = "darkgreen";
				sPxdeAUSCcq = 0;
				sIeQGGfdTC = 0;
				REafbyOsmM = nil;
			end	
		end
		if (TPjuFQLAwFiLLEv == 1 or tAhFKIffvdXxXmyd:IsVisible()) then
			local jKHlIThlERJe = GetBattlefieldWinner();
			if (jKHlIThlERJe ~= nil) then
      		DPpadygpHapDFmW:SetTexture(1,0,1)
				DPpadygpHapDFmW2:SetTexture(1,0,1)
				qUBJqmSlBcOLbB = "pink";
				if (LQrDAWOzbgNBmB == 0) then
					DEFAULT_CHAT_FRAME:AddMessage("AutoLeave BG in 15 sec", 0, 0.7, 1);
					hIJqJGjb = GetTime()+15;
					LQrDAWOzbgNBmB = 1;
				end
			end

			if (hIJqJGjb <= iDNHreSSkPuWb and LQrDAWOzbgNBmB == 1) then
				LeaveBattlefield();
				hIJqJGjb = 0;
			end
		end
	end
	if (nvbJCHnOmyqFxpH == 1 or tAhFKIffvdXxXmyd:IsVisible()) then
			if (JvspddiutOljh <= iDNHreSSkPuWb and qqnVdQmyno == 1) then
				StaticPopup_Hide("DEATH");
				RepopMe();
				qqnVdQmyno = 0;
				JvspddiutOljh = 0;
			end
		end
end


function WVipWUbGTtp()
	local zone = GetRealZoneText();
	local zoneNr2 = GetCurrentMapZone();

	if IsInBg == 1 then
		rbfNsNvzzIjpbEc = zone;
		jIfgthcRUwx = GetTime()+1;
		hPWmBtufsDHnS = 0;
		if (qUBJqmSlBcOLbB == "white" or qUBJqmSlBcOLbB == nil) then
			DPpadygpHapDFmW:SetTexture(0,0,1)
			DPpadygpHapDFmW2:SetTexture(0,0,1)
			qUBJqmSlBcOLbB = "blau";
		end
	else
		rbfNsNvzzIjpbEc = nil;
		if ((VhmdKDeAVJ == 1) and (hPWmBtufsDHnS == 0)) then
			PlaySoundFile("Interface\\AddOns\\GaduGadu\\xQTDqsBVHEEq.mp3");
		end
		if ((QSjVyBgKbQv == 1) and (hPWmBtufsDHnS == 0)) then
			SendChatMessage("BG over","WHISPER", GetDefaultLanguage("player"), aIzSlgrzhUVAbyX);
		end
		GaduGadu.BgBegun = 0;
		LQrDAWOzbgNBmB = 0;
		DPpadygpHapDFmW:SetTexture(1,1,1)
		DPpadygpHapDFmW2:SetTexture(1,1,1)
		qUBJqmSlBcOLbB = "white";
		hPWmBtufsDHnS = 1;
		hIJqJGjb = 0;
		qqnVdQmyno = 0;
		hrolTnx = 0;
	end
	if zoneNr == 11 and zoneNr2 ~= 11 then
	   DeclineGroup();
	   zoneNr = 0;
	end
end
